module WxRide
	class ErrorDialog < Dialog
		include Wx
		def ErrorDialog.fatal(msg,title,error)
			mb = self.new(title)
			mb.msg = msg
			mb.error = error
			mb.show_modal
		end
  
		ID_DETAILS = 4000
		def initialize(title)
			super(nil,-1,title)
			# Split the window into three Parts for Top Section, Horizontal Rule and Dialog Messages
			vbox = BoxSizer.new(VERTICAL)
			# Split the window into three parts, Icon, Message, and Buttons
			hbox = BoxSizer.new(HORIZONTAL)
			hbox.add(StaticBitmap.new(self,-1,
						ArtProvider::get_bitmap(ART_ERROR,ART_FRAME_ICON,[32,32]),[0,0],[32,32]),0,
						0)
			hbox.add_spacer(10)
			hbox.add(@msg = StaticText.new(self,-1,""),1,EXPAND)
			hbox.add_spacer(10)
    
			# Buttons for Action
			bbox = BoxSizer.new(VERTICAL)
			bbox.add(Button.new(self,ID_OK,"&Ok"),0)
			bbox.add(@dt = Button.new(self,ID_DETAILS,"&Details>>"),0)
			hbox.add(bbox,0,EXPAND)
			vbox.add(hbox,1,EXPAND)
			vbox.add(@err = TextCtrl.new(self,-1,"",DEFAULT_POSITION,DEFAULT_SIZE,TE_READONLY|TE_MULTILINE),3,EXPAND)
			@err.show(false)
			set_sizer(vbox)
			@min_size = Wx::Size.new(775,50)
			@max_size = Wx::Size.new(775,300)
			self.set_min_size(@min_size)
			self.set_max_size(@max_size)
			evt_button(ID_DETAILS) do
				if @err.is_shown
					@err.hide
					@dt.set_label("&Details>>")
					self.set_size(@min_size)
					self.fit()
				else
					@err.show
					@dt.set_label("<<&Details")
					self.set_size(@max_size)
					self.fit()
				end
			end
		end
  
		def msg=(msg)
			@msg.set_label(msg)
			self.layout()
			self.fit()
		end
  
		def error=(error)
			@err.set_value(error)
		end
	end
end